<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class GoodsCategory extends Model
{
    public static function getCategoryTree($pid = 0)
    {
        $children = static::wherePid($pid)->get();
        if (!$children->isEmpty()) {
            foreach ($children as $key => $category) {
                $children[$key]['_children'] = static::getCategoryTree($category->id);
            }
            return $children;
        } else {
            return [];
        }
    }
}
